<?php
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
namespace app\common\model;
use think\Model;
class Vodtv extends Model {
    public function tv_updata($id,$sid,$name=''){
        $rs = db('Vodtv');
        $data['vodtv_id'] = $id;
        $data['vodtv_sid'] = $sid;
        $rs->where($data)->delete();
        if (!empty($name) && !empty($id) && !empty($sid)){
            if (is_array($name)) {
                $names = $name;
            } else {
                $names = explode(',', $name);
            }
            $names = array_unique($names);
            foreach($names as $key => $val) {
                if ($val == "未知" || empty($val)) {
                    continue;
                }
                $datas[$key]['vodtv_id'] = $id;
                $datas[$key]['vodtv_sid'] = $sid;
                $datas[$key]['vodtv_name'] = $val;
            }
            if (isset($datas)) {
                $rs->insertAll($datas);
            }
        }
    }	
    //获取相关的数据转为字符串
    public function tv_data($id,$sid) {
        $rs = db("vodtv");
        $data['vodtv_id'] = $id;
        $data['vodtv_sid'] = $sid;
        $list = $rs->where($data)->column('vodtv_name');
        return $list;
    }
    public function tv_add($id,$cid,$sid){
		if(!empty($cid) && !empty($id) && !empty($sid)) {
        $rs = db("Vodtv");
        $data['vodtv_id'] = $id;
        $data['vodtv_name'] = $cid;
        $data['vodtv_sid'] = $sid;
        $rs->where($data)->delete();
        $rs->insert($data);
		}
    }
}